import argparse

# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# ROOT_DIR = BASE_DIR
# sys.path.append(os.path.join(ROOT_DIR, 'pointnet2'))


def parse_option():
    parser = argparse.ArgumentParser()
    parser.add_argument('--train', action='store_true')
    parser.add_argument('--show', action='store_true')
    parser.add_argument("--seed", type=int, default=42, help='manual seed')

    # Model
    parser.add_argument('--fix_err', action='store_true')
    parser.add_argument('--fix_err_rate', default=1.0, type=float, help='rate after the fix_err')
    parser.add_argument('--fix_mode', type=str, default='cat', choices=['add','cat'], help='mode for fix_err')
    parser.add_argument('--pam_inner_dim', default=64, type=int, help='pam dconv features')
    parser.add_argument('--pam_out_dim', default=3, type=int, help='pam output features')
    # parser.add_argument('--tem_nfeat', default=64, type=int, help='tem num features')
    parser.add_argument('--frm_input', default=3, type=int, help='pam output features')
    parser.add_argument('--frm_output', default=3, type=int, help='pam output features')
    parser.add_argument('--tem_input', default=3, type=int, help='pam output features')
    parser.add_argument('--tem_output', default=64, type=int, help='pam output features')
    # parser.add_argument('--num_target', type=int, default=256, help='Proposal number [default: 256]')
    # parser.add_argument('--sampling', default='kps', type=str, help='Query points sampling method (kps, fps)')

    # Transformer
    parser.add_argument('--num_heads', default=1, type=int, help='multi-head number')
    parser.add_argument('--channels', default=24, type=int, help='multi-head number')
    parser.add_argument('--num_classes', default=4, type=int, help='multi-head number')
    parser.add_argument('--dropout', default=0.5, type=float, help='multi-head number')
    parser.add_argument('--kdim', default=256, type=int, help='multi-head number')
    parser.add_argument('--vdim', default=256, type=int, help='number of decoder layers')
    parser.add_argument('--embed_dim', default=128, type=int, help='dim_feedforward')
    # parser.add_argument('--transformer_dropout', default=0.1, type=float, help='transformer_dropout')
    # parser.add_argument('--transformer_activation', default='relu', type=str, help='transformer_activation')
    # parser.add_argument('--self_position_embedding', default='loc_learned', type=str,
    #                     help='position_embedding in self attention (none, xyz_learned, loc_learned)')
    # parser.add_argument('--cross_position_embedding', default='xyz_learned', type=str,
    #                     help='position embedding in cross attention (none, xyz_learned)')

    # Loss
    # parser.add_argument('--loss_type', default='mse', type=str, help='choose which loss to use')
    # parser.add_argument('--query_points_generator_loss_coef', default=0.8, type=float)
    # parser.add_argument('--obj_loss_coef', default=0.1, type=float, help='Loss weight for objectness loss')
    # parser.add_argument('--box_loss_coef', default=1, type=float, help='Loss weight for box loss')
    # parser.add_argument('--sem_cls_loss_coef', default=0.1, type=float, help='Loss weight for classification loss')
    # parser.add_argument('--center_loss_type', default='smoothl1', type=str, help='(smoothl1, l1)')
    # parser.add_argument('--center_delta', default=1.0, type=float, help='delta for smoothl1 loss in center loss')
    # parser.add_argument('--size_loss_type', default='smoothl1', type=str, help='(smoothl1, l1)')
    # parser.add_argument('--size_delta', default=1.0, type=float, help='delta for smoothl1 loss in size loss')
    # parser.add_argument('--heading_loss_type', default='smoothl1', type=str, help='(smoothl1, l1)')
    # parser.add_argument('--heading_delta', default=1.0, type=float, help='delta for smoothl1 loss in heading loss')
    # parser.add_argument('--query_points_obj_topk', default=4, type=int, help='query_points_obj_topk')
    # parser.add_argument('--size_cls_agnostic', action='store_true', help='Use class-agnostic size prediction.')

    # Data
    parser.add_argument('--batch_size', type=int, default=4, help='Batch Size per GPU during training [default: 8]')
    parser.add_argument('--dataset', default='Ballet', type=str, help='shark ,rena or ballet')
    # parser.add_argument('--num_point', type=int, default=50000, help='Point Number [default: 50000]')
    parser.add_argument('--data_root', default='data/vsat_data_v3', help='data root path')
    parser.add_argument('--img_size', type=int, default=128, help='cut img size')
    # parser.add_argument('--use_height', action='store_true', help='Use height signal in input.')
    # parser.add_argument('--use_color', action='store_true', help='Use RGB color in input.')
    # parser.add_argument('--use_sunrgbd_v2', action='store_true', help='Use V2 box labels for SUN RGB-D dataset')
    parser.add_argument('--num_workers', type=int, default=4, help='num of workers to use')

    # Training
    parser.add_argument('--init', action='store_false')
    # parser.add_argument('--pretrained', action='store_true', help='whether to use pretrained')
    parser.add_argument('--start_epoch', type=int, default=1, help='Epoch to run [default: 1]')
    parser.add_argument('--max_epoch', type=int, default=400, help='Epoch to run [default: 180]')

    parser.add_argument('--lr', type=float, default=1e-4, help='init lr')
    parser.add_argument('--optimizer', type=str, default='adam',choices=['adam','sgd','adamw'], help='optimizer')
    parser.add_argument('--momentum', type=float, default=0.9, help='momentum for SGD')
    parser.add_argument('--weight_decay', type=float, default=0.0005,
                        help='Optimization L2 weight decay [default: 0.0005]')
    
    parser.add_argument('--lr_scheduler', type=str, default='Plateau', choices=['Plateau','step',"cosine"], help='mode for ReduceLROnPlateau')
    parser.add_argument('--factor', type=float, default=0.5, help='factor of ReduceLROnPlateau')
    parser.add_argument('--patience', type=int, default=4, help='patience of ReduceLROnPlateau')
    parser.add_argument('--warmup-epoch', type=int, default=-1, help='warmup epoch')
    # parser.add_argument('--decoder_learning_rate', type=float, default=0.0004,
    #                     help='Initial learning rate for decoder [default: 0.0004]')
    # parser.add_argument('--warmup-multiplier', type=int, default=100, help='warmup multiplier')
    parser.add_argument('--lr_decay_epochs', type=int, default=[560, 700], nargs='+',
                        help='for step scheduler. where to decay lr, can be a list')
    parser.add_argument('--lr_decay_rate', type=float, default=0.1,
                        help='for step scheduler. decay rate for learning rate')
    # parser.add_argument('--clip_norm', default=0.1, type=float,
    #                     help='gradient clipping max norm')
    parser.add_argument('--bn_momentum', type=float, default=0.1, help='Default bn momeuntum')
    # parser.add_argument('--syncbn', action='store_true', help='whether to use sync bn')

    parser.add_argument('--loss', type=str, default='mse', choices=['mse','auto'], help='loss')

    # log
    parser.add_argument('--checkpoint_path', default=None, type=str, help='Model checkpoint path [default: None]')
    parser.add_argument('--log_dir', default='log', help='Dump dir to save model checkpoint [default: log]')
    parser.add_argument('--exp_name', default='exp_1', help='Dump dir to save model checkpoint [default: log]')
    parser.add_argument('--print_freq_train', type=int, default=100, help='print frequency')
    parser.add_argument('--print_freq_test', type=int, default=100, help='print frequency')
    parser.add_argument('--save_freq', type=int, default=80, help='save frequency')
    parser.add_argument('--val_freq', type=int, default=10, help='val frequency')

    # distribute
    parser.add_argument("--local_rank", type=int, help='local rank for DistributedDataParallel')
    parser.add_argument('--distributed', action='store_true', help='whether to use dist')
    parser.add_argument('--default_gpu', type=int, default=0, help='whether to use dist')
    # parser.add_argument('--ap_iou_thresholds', type=float, default=[0.25, 0.5], nargs='+',
    #                     help='A list of AP IoU thresholds [default: 0.25,0.5]')
    # parser.add_argument("--rng_seed", type=int, default=0, help='manual seed')

    args, unparsed = parser.parse_known_args()

    return args